package admin

import (
	"context"

	"oil-station-backend/internal/svc"
	"oil-station-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetInventoryLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetInventoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetInventoryLogic {
	return &GetInventoryLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetInventoryLogic) GetInventory() (resp []types.Inventory, err error) {
	// 获取所有库存信息
	inventories, err := l.svcCtx.InventoryModel.FindAll()
	if err != nil {
		return nil, err
	}

	// 转换为API响应格式
	var result []types.Inventory
	for _, inv := range inventories {
		result = append(result, types.Inventory{
			Id:       inv.Id,
			FuelType: inv.FuelType,
			Stock:    inv.Stock,
			MinStock: inv.MinStock,
			MaxStock: inv.MaxStock,
		})
	}

	return result, nil
}